<template>
	<view class="page">
		<view class="body">
			<Sub-title label="目录" />
			<view class="list" v-for="(item,index) in tabList" :key="index" @tap.stop="Jump(`/pages/home/bookDetails?id=${item.id}`)">
				{{item.directory}}
			</view>
			<u-loadmore :status="status" />
		</view>
	</view>
</template>

<script>
	import {
		bookDirectory
	} from "@/request/homeApi.js";
	export default {

		data() {
			return {
				queryForm: {
					book_lists_id: '',
					page: 1,
					limit: 26,
				},
				tabList: [],
				last_page:1,
				status: "nomore", // 加载状态
			};
		},
		onLoad(e) {
			this.queryForm.book_lists_id = e.id
			this.getList();
		},

		onReachBottom() {
			let that = this
			if (that.queryForm.page < that.last_page) {
				that.queryForm.page = that.queryForm.page + 1
				that.getList()
			}
		},
		// 监听页面滚动
		onPageScroll(scroll) {
			uni.$emit("onPageScroll", scroll.scrollTop);
		},
		methods: {
			Jump(url){
				uni.navigateTo({
					url:url
				})
			},
			// 获取详情
			getList() {
				let that = this
				bookDirectory(that.queryForm).then((res) => {
					if (res.code == 200) {
						that.tabList = that.tabList.concat(res.data.list)
						that.last_page = Math.ceil(res.data.count / res.data.list.length)
						res.data.count == 0 ? that.status = 'nomore' : that.status = ''
					}
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	.page {
		.body {
			width: 100%;
			padding: 20rpx 24rpx;
			min-height: 100rpx;
			box-sizing: border-box;
			background-color: #D2E4D6;
			margin-top: -14rpx;
			height: 100vh;
			overflow-y: auto;
			
			.list{
				height: 60rpx;
				line-height: 60rpx;
				font-size: 30rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}			
		}
	}
</style>